Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests demonstrating string array hashmap usage #22311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

allocgator
Copy link
Contributor

@allocgator allocgator commented Dec 25, 2024

There are limited examples of using a StringArrayHashMap.

This PR has examples of general operations that can be performed using this data structure.

@Vexu
Copy link
Member

Vexu commented Dec 25, 2024

If this demonstrates usage it should be a decltest.

@allocgator
Copy link
Contributor Author

allocgator commented Dec 26, 2024

I wanted to give examples of StringArrayHashMap similar to the test "basic hash map usage" block above it.

A few questions about decltests:

  1. Is the test block here a decltest for insert ?

  2. If we take the contains method as an example, would the decltest be displayed here ?

@allocgator
Copy link
Contributor Author

Hi @Vexu,

I'm not confident on how to proceed - by decltest do you mean:

  • rename test "string array hashmap usage" to test StringArrayHashMap ?

  • or, test declarations for methods in ArrayHashMapWithAllocator, like:

    /// Inserts a key-value pair into the hash map, asserting that no previous
    /// entry with the same key is already present
    pub fn putNoClobber(self: *Self, key: K, value: V) !void {
        return self.unmanaged.putNoClobberContext(self.allocator, key, value, self.ctx);
    }
        
    test putNoClobber {
        var map = StringArrayHashMap([]i32).init(std.testing.allocator);
        defer map.deinit();
          
        var foo_values = [_]i32{ 11, 22 };
        try map.putNoClobber("foo", &foo_values);
         
        try testing.expectEqualSlices(i32, map.get("foo").?, &[_]i32{ 11, 22 });
    }
    

@Vexu
Copy link
Member

Vexu commented Jan 16, 2025

I think having decltests for the methods of all standard containers would be good (for the basic versions so for insert but not for insertAssumeCapacity). A much simpler decltest for StringArrayHashMap and others showing basic init, deinit and one or two of the most common operations would probably also be good but I'd ask for more opinions on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants